babl: add rendering intent argument to icc loading API
authorØyvind Kolås <pippin@gimp.org>
Fri, 8 Sep 2017 19:26:04 +0000 (21:26 +0200)
committerØyvind Kolås <pippin@gimp.org>
Wed, 13 Sep 2017 21:00:18 +0000 (23:00 +0200)
babl/babl-icc.c
babl/babl.h
tools/babl-icc-rewrite.c

index 7d7905139904ce665d7a87864c64b50df288ba61..7b647329df9471296f9ed02fb98e2d67e7606c2b 100644 (file)
@@ -671,6 +671,7 @@ static char *decode_string (ICC *state, const char *tag, const char *lang, const
 const Babl *
 babl_space_from_icc (const char   *icc_data,
                      int           icc_length,
+                     BablIccIntent intent,
                      const char  **error)
 {
   ICC  *state = icc_state_new ((char*)icc_data, icc_length, 0);
@@ -684,6 +685,7 @@ babl_space_from_icc (const char   *icc_data,
 
   sign_t profile_class, color_space;
 
+
   if (!error) error = &int_err;
   *error = NULL;
 
@@ -710,6 +712,34 @@ babl_space_from_icc (const char   *icc_data,
   }
   }
 
+  switch (intent)
+  {
+    case BABL_ICC_INTENT_RELATIVE_COLORIMETRIC:
+      /* that is what we do well */
+      break;
+    case BABL_ICC_INTENT_PERCEPTUAL:
+      /* if there is an A2B0 and B2A0 tags, we do not do what that
+       * profile is capable of - since the CLUT code is work in progress
+       * not in git master yet.
+       */
+      if (icc_tag (state, "A2B0", NULL, NULL) &&
+          icc_tag (state, "B2A0", NULL, NULL))
+      {
+        *error = "profile contains perceptual luts and perceptual was explicitly asked for, babl does not yet support CLUTs";
+      }
+      else
+      {
+        intent = BABL_ICC_INTENT_RELATIVE_COLORIMETRIC;
+      }
+      break;
+    case BABL_ICC_INTENT_ABSOLUTE_COLORIMETRIC:
+      *error = "absolute colormetric not implemented";
+      break;
+    case BABL_ICC_INTENT_SATURATION:
+      *error = "absolute stauration not supported";
+      break;
+  }
+
   {
      int offset, element_size;
      if (!*error && icc_tag (state, "rTRC", &offset, &element_size))
index 80f342b47887a0fb3013ab088c6eaf97f6a8ea6a..a7d75b560279058492367448d68d813b44f0d30e 100644 (file)
@@ -90,6 +90,13 @@ const Babl * babl_model     (const char *name);
  */
 const Babl * babl_space (const char *name);
 
+typedef enum {
+  BABL_ICC_INTENT_PERCEPTUAL             = 0,
+  BABL_ICC_INTENT_RELATIVE_COLORIMETRIC  = 1,
+  BABL_ICC_INTENT_SATURATION             = 2,
+  BABL_ICC_INTENT_ABSOLUTE_COLORIMETRIC  = 3
+} BablIccIntent;
+
 /**
  * babl_space_from_icc:
  *
@@ -101,10 +108,12 @@ const Babl * babl_space (const char *name);
  *         if an error occurs, NULL is returned and an error message
  *         is provided in error.
  *
- * Create a babl space from an in memory ICC profile, the
- * profile does no longer need to be loaded for the space to work,
- * multiple calls with the same icc profile and same icc_transform 
- * will result in the same space.
+ * Create a babl space from an in memory ICC profile, the profile does no
+ * longer need to be loaded for the space to work, multiple calls with the same
+ * icc profile and same intent will result in the same babl space.
+ *
+ * On a profile that doesn't contain A2B0 and B2A0 CLUTs perceptual and
+ * relative-colorimetric intents are treated the same.
  *
  * If a BablSpace cannot be created from the profile NULL is returned and a
  * static string is set on the const char *value pointed at with &value
@@ -113,6 +122,7 @@ const Babl * babl_space (const char *name);
  */
 const Babl *babl_space_from_icc (const char       *icc_data,
                                  int               icc_length,
+                                 BablIccIntent     intent,
                                  const char      **error);
 
 /* babl_icc_get_key:
@@ -128,6 +138,7 @@ const Babl *babl_space_from_icc (const char       *icc_data,
  * "copyright", "manufacturer", "device", "profile-class", "color-space" and
  * "pcs".
  */
+
 char *babl_icc_get_key (const char *icc_data,
                         int         icc_length,
                         const char *key,
index 0746d506a47d1965269639da1f380d4e9d0ec00a..f30b20e5b34c80da01c91ce98f33ee39acd88726 100644 (file)
@@ -79,7 +79,7 @@ main (int    argc,
       free (str);
     }
   }
-  babl = babl_space_from_icc (icc_data, icc_len, &error);
+  babl = babl_space_from_icc (icc_data, icc_len, 0, &error);
   free (icc_data);
   if (error || !babl)
   {